// @FileName  :bst.c
// @Time      :2024/4/25 18:51
// @Author    :YKW
//# include <bits/stdc++.h>
//using namespace std;
# include <stdio.h>
# include <stdlib.h>
# include <math.h>
# include <string.h>
# include <stdlib.h>

typedef struct node {
    int v, d;
    struct node *p, *l, *r;
} node;
int num, root;

void insert(node *par, int value) {
    if (root == 0) {
        root = 1;
        par->v = value;
        par->d = 1;
        par->l = par->r = NULL;
    } else {
        if (par->v <= value) {
            if (par->r == NULL) {
                node *new = (node *) malloc(sizeof(node));
                new->p = par;
                new->d = par->d + 1;
                new->v = value;
                new->l = new->r = NULL;
                par->r = new;
            } else insert(par->r, value);
        } else {
            if (par->l == NULL) {
                node *new = (node *) malloc(sizeof(node));
                new->p = par;
                new->d = par->d + 1;
                new->v = value;
                new->l = new->r = NULL;
                par->l = new;
            } else insert(par->l, value);
        }
    }
}

void out(node *cur) {
    if (cur->l != NULL) out(cur->l);
    if (cur->l == NULL && cur->r == NULL) printf("%d %d\n", cur->v, cur->d);
    if (cur->r != NULL) out(cur->r);
}

int main() {
    setbuf(stdout, NULL);
    node *head = (node *) malloc(sizeof(node));
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &num);
        insert(head, num);
    }
    out(head);
}
